package com.nk.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nk.system.beans.HistoryBean;
import com.nk.system.common.search.Search;
import com.nk.system.dao.UserStatDao;
import com.nk.system.domain.UserStat;
import com.nk.system.service.HistoryService;

@Service("historyService")
public class HistoryServiceImpl extends GenericServiceImpl<UserStat, Integer, UserStatDao>  implements HistoryService{

	@Autowired
	public HistoryServiceImpl(UserStatDao userStatDao) {
		super(userStatDao);
	}

	@Override
	public List<HistoryBean> getHistry(int id) {
		// TODO Auto-generated method stub
		List<HistoryBean> historyList = new ArrayList<HistoryBean>();
		
		Search search = new Search(UserStat.class);
		search.addFilterEqual("userid", id);
		search.addSortDesc("date");

		List<UserStat> userStatList = dao.search(search);
		
		int num=0;
		for(UserStat userHis:userStatList){
			if(num<=5) {
				HistoryBean historyBean = new HistoryBean(); 
				historyBean.setUname(userHis.getUname());
				historyBean.setFaculty(userHis.getFaculty());
				historyBean.setMajor(userHis.getMajor());
				historyBean.setDate(userHis.getDate());
				historyBean.setPercent(userHis.getPercent());
				historyBean.setScore(userHis.getScore());
				
				historyList.add(historyBean);
				num++;
			}
		}
		
		
		return historyList;
		
	}



	
	
	
}
